﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using XMK.Framework.Model;
using XMK.Tadong.DataSearch.Data;
using XMK.Framework.ElasticSearch;
using XMK.Utils;

namespace XMK.Tadong.DataSearch.Biz
{
    public class XMKFileSearchBiz
    {
        /// <summary>
        /// 该方法目前接受5个参数
        /// pageindex 页号，默认为1
        /// pagesize 每页数据条数，默认为1
        /// keyw 搜索关键词，没有输入则传入空字符串
        /// biz_obj 业务对象，多个用逗号隔开，不允许有空格，没有输入则传入空字符串
        /// dest_obj 目标对象，多个用逗号隔开，不允许有空格，如430,440，没有输入则传入空字符串
        /// </summary>
        /// <param name="ps"></param>
        /// <returns></returns>
        public ResponseInfo QueryXmkFileList(IEnumerable<KeyValuePair<string, string>> ps)
        {
            ResponseInfo response = null;
            try
            {
                PageInfo pageInfo = new PageInfo();
                pageInfo.CurrentPage = ParseHelper.Parse<int>(ps.Where(p => p.Key.ToLower().Equals("pageindex")).Select(p => p.Value).FirstOrDefault(), 1);
                pageInfo.PageSize = ParseHelper.Parse<int>(ps.Where(p => p.Key.ToLower().Equals("pagesize")).Select(p => p.Value).FirstOrDefault(), 1);
                ElasticSearchConnection conn =
                    new ElasticSearchConnection(DataSearchConfig.ESHost, DataSearchConfig.Port, DataSearchConfig.IndexName, ConnectionType.Thrift);
                XMKFileSearchData data = new XMKFileSearchData(conn);
                response = new ResponseInfo();
                response.Data = data.QueryXmkFileList(ps, pageInfo);
                response.Page = pageInfo;
            }
            catch (Exception ex)
            {
                //生成返回对象（带错误信息）
                response = new ResponseInfo("error！");
                LogHelper.WriteLog(LogType.Error, "[ButtonList:]" + ex.ToString());
            }
            return response;
        }


    }
}
